//
//  YMIntroductionViewController.m
//  YMPAY
//
//  Created by yameng on 14-6-4.
//  Copyright (c) 2014年 YAMENG. All rights reserved.
//

#import "YMIntroductionViewController.h"
#import "MYIntroductionPanel.h"
//#import "LoginViewController.h"

@interface YMIntroductionViewController ()
{
    MYBlurIntroductionView *introductionView;
    UIImageView *backImage;
}

@end

@implementation YMIntroductionViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

-(void)viewDidAppear:(BOOL)animated
{
    self.view.backgroundColor = [UIColor clearColor];
    
    backImage = [[UIImageView alloc] init];
    backImage.frame = CGRectMake(0.0f, 0.0f, kDeviceWidth, kDeviceHeight);
    backImage.image = [UIImage imageNamed:@"introduction_bg"];
    [self.view addSubview:backImage];
    
    
    NSString *imageNameFormat = @"introduction_%d";
    
    NSMutableArray *panelArray = [NSMutableArray arrayWithCapacity:3];
    for (int i = 1; i<=3; i++) {
        MYIntroductionPanel *panel = [[MYIntroductionPanel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) image:[UIImage imageNamed:[NSString stringWithFormat:imageNameFormat,i]]];
        [panelArray addObject:panel];
    }
    
    introductionView = [[MYBlurIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    introductionView.delegate = self;
    [introductionView buildIntroductionWithPanels:panelArray];
    [self.view addSubview:introductionView];
}

#pragma mark - Sample Delegate Methods

-(void)introduction:(MYBlurIntroductionView *)introductionView didChangeToPanel:(MYIntroductionPanel *)panel withIndex:(NSInteger)panelIndex{
    NSLog(@"Introduction did change to panel %d", (int)panelIndex);
}

-(void)introduction:(MYBlurIntroductionView *)introductionView didFinishWithType:(MYFinishType)finishType {
    NSLog(@"Introduction did finish");
    
    
    //读取沙盒数据
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WelcomeWhenFirstStart"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [backImage removeFromSuperview];
    backImage = nil;
    
    [self.view removeFromSuperview];
    self.view = nil;
    
    kAPPDelegate.introductVC = nil;
    
    [kAPPDelegate loginView];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
@end
